<html xmlns:saxon="http://icl.com/saxon">
   <head>
      <link rel="stylesheet" type="text/css" href="doc.css"/>
      <link rel="stylesheet" type="text/css" href=""/>
      <meta author="The MathWorks Ltd."/>
      <meta copyright="2011 The MathWorks Ltd."/>
      <title>Minimize and maximize</title>
   </head>

   
    <body>
      <table class="header" width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
            <td bgcolor="#e4f0f8"><A href="User guide.html"><font face="Arial" bgcolor="#e4f0f8" size="+0" underline="0" color="#000000"><b>User guide</b></font></A></td>
            <td width="36" bgcolor="#e4f0f8"><A HREF="User guide5_1.html"><IMG SRC="Images/leftarrow.png" BORDER="0" ALT="previous page"/></A><A HREF="User guide5_3.html"><IMG SRC="Images/rightarrow.png" BORDER="0" ALT="next page"/></A></td>
         </tr>
      </table>
   

      <br clear="all"/>
          
      <h2>5.2: Minimize and maximize&nbsp;<a href="User guide5.html"><img src="Images/uparrow.png" border="0" align="top" alt="Go back up one level"/></a></h2>
      
        <p>
            When a <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a> has its "MinimizeFcn"
            filled in, a minimize/maximize button (<img src="Images/panelMinimize.png"/> / <img src="Images/panelMaximize.png"/>) is shown in the upper-right of the
            title-bar. When the user clicks this button the specified function
            is called. Since the behaviour of the parent container is
            different in different use-cases, it is up to the user to write
            some code to actually resize the panel. Note that minimizing
            a panel to its title-bar only really makes sense inside a 
            <a href="uiextras.VBox.html"><code class="FUNCTION">uiextras.VBox</code></a> or <a href="uiextras.VBoxFlex.html"><code class="FUNCTION">uiextras.VBoxFlex</code></a>.
                 </p>
                 <p>The following simple example shows how to add minimize/maximize
                     functionality to a box full of panels. Save the code into
                 a file called "dockexample.m" to run it.</p>
                 
                 <p>(The code for this example can be found here: 
                     [ <a href="Examples/minimizeexample.m">view</a>
                     | <a href="matlab: edit(fullfile(layoutRoot,'layoutHelp','Examples','minimizeexample.m'))">edit</a>
                     | <a href="matlab: p=pwd();cd(fullfile(layoutRoot,'layoutHelp','Examples')); minimizeexample; cd(p)">run</a> ]
                 )</p>
                 
                 
                 <h4>Create the layout with three panels</h4>
            <p>Open a new figure window and add three panels.</p>
            <example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"><a href="matlab:doc function"><code class="FUNCTION">function</code></a> minimizeexample()
width = 200;
pheightmin = 20;
pheightmax = 100;

<code class="COMMENT">% Create the window and main layout</code>
fig = <a href="matlab:doc figure"><code class="FUNCTION">figure</code></a>( <code class="STRING">'Name'</code>, <code class="STRING">'Collapsable GUI example'</code>, ...
              <code class="STRING">'NumberTitle'</code>, <code class="STRING">'off'</code>, ...
              <code class="STRING">'Toolbar'</code>, <code class="STRING">'none'</code>, ...
              <code class="STRING">'MenuBar'</code>, <code class="STRING">'none'</code> );
box = <a href="uiextras.VBox.html"><code class="FUNCTION">uiextras.VBox</code></a>( 'Parent', fig );

panel{1} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 1'</code>, <code class="STRING">'Parent'</code>, box );
panel{2} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 2'</code>, <code class="STRING">'Parent'</code>, box );
panel{3} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 3'</code>, <code class="STRING">'Parent'</code>, box );
<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( box, 'Sizes', pheightmax*ones(1,3) );

<code class="COMMENT">% Add some contents</code>.
<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 1'</code>, <code class="STRING">'Parent'</code>, panel{1} );
<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 2'</code>, <code class="STRING">'Parent'</code>, panel{2} );
<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 3'</code>, <code class="STRING">'Parent'</code>, panel{3} );

<code class="COMMENT">% Resize the window</code>
pos = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( fig, <code class="STRING">'Position'</code> );
<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( fig, <code class="STRING">'Position'</code>, [pos(1,1:2),width,sum(box.Sizes)] );</font></pre>
            <p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample1.png"/></center></font></p>
        </example>
        
            <h4>Add the minimize/maximize callback</h4>
            <p>We set each panel to call the same minimize/maximize function.
        This function is nested inside the main function so that it has access
    to the main function's variables. A better way to do this is to make the
main function into a class, but this nested-function approach is fine
for simple applications.</p>
            <p>Note that as soon as we set the "MinimizeFcn" property the minimize/maximize
                icon appears in the top-right of each panel. We use a cell-array to pass an
            extra argument, the panel number, to the minimize function. This extra argument appears after the usual
            <code>eventSource</code> and <code>eventData</code> arguments.</p>
            <example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"><code class="COMMENT">% Hook up the minimize callback</code>.
<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{1}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 1} );
<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{2}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 2} );
<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{3}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 3} );

<code class="COMMENT">%-------------------------------------------------------------------------%</code><br/> 
    <a href="matlab:doc function"><code class="FUNCTION">function</code></a> nMinimize( eventSource, eventData, whichpanel )
        <code class="COMMENT">% A panel has been maximized/minimized</code>
        s = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( box, <code class="STRING">'Sizes'</code> );
        pos = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( fig, <code class="STRING">'Position'</code> );
        panel{whichpanel}.IsMinimized = ~panel{whichpanel}.IsMinimized;
        <a href="matlab:doc if"><code class="FUNCTION">if</code></a> panel{whichpanel}.IsMinimized
            s(whichpanel) = pheightmin;
        <a href="matlab:doc else"><code class="FUNCTION">else</code></a>
            s(whichpanel) = pheightmax;
        <a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;
        <a href="matlab:doc set"><code class="FUNCTION">set</code></a>( box, <code class="STRING">'Sizes'</code>, s );
        
        <code class="COMMENT">% Resize the figure, keeping the top stationary</code>
        delta_height = pos(1,4) - <a href="matlab:doc sum"><code class="FUNCTION">sum</code></a>( box.Sizes );
        <a href="matlab:doc set"><code class="FUNCTION">set</code></a>( fig, <code class="STRING">'Position'</code>, pos(1,:) + [0 delta_height 0 -delta_height] );
    <a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;<code class="COMMENT">% Minimize</code>&nbsp;

<a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;<code class="COMMENT">% Main function</code></font></pre>
            <p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample2.png"/></center></font></p>
        </example>
        
    
            <h4>Click the minimize buttons</h4>
            <p>Minimizing the middle panel causes it to shrink to just its 
            title-bar and the window shrinks accordingly. The
    "Minimize" icon is replaced by a "Maximise" icon.</p>
            <example><p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample3.png"/></center></font></p></example>
            <p> Re-maximizing the panel would
            cause it to re-appear in full and the window to grow again.</p>

        
      
      <br clear="ALL"/>
      <table class="footer" width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
            <td width="18" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide5_1.html"><img src="images/leftarrow.png" border="0" alt="previous page"/></a></td>
            <td width="40%" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide5_1.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Context help</font></a></td>
            <td width="20%" height="15" bgcolor="#e4f0f8" align="center"><a href="index.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">[Top]</font></a></td>
            <td width="40%" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide5_3.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Dock and undock</font></a></td>
            <td width="18" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide5_3.html"><img src="images/rightarrow.png" border="0" alt="next page"/></a></td>
         </tr>
      </table>
      <font face="Arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">&copy; 2011 The MathWorks Ltd</font>
      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/license.txt'])">Terms of Use</a>
      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/patents.txt'])">Patents</a>
      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/trademarks.txt'])">Trademarks</a>
   
   </body>
</html>
        
